﻿using ControleRepresentante.Data.Catalogs;
using ControleRepresentante.Data.Helpers;

namespace ControleRepresentante.Data.CatalogSteps
{
    internal class ChangeCodigoJolitexToString : CatalogStepBase<ControleRepresentanteCatalogStepTypes>
    {
        protected override ControleRepresentanteCatalogStepTypes CatalogStepType
        {
            get { return ControleRepresentanteCatalogStepTypes.ChangeCodigoJolitexToString; }
        }

        public override void Execute(IDataAccess dataAccess)
        {
            CatalogStepHelper catalogStepHelper = new CatalogStepHelper(dataAccess);
            TableHelper pedidoJolitex = catalogStepHelper.GetTable("PedidoJolitex");
            pedidoJolitex.AddColumn("CodigoTemp", ColumnType.ShortString, true, false);
            dataAccess.ExecuteCommand(@"
                UPDATE PedidoJolitex
                SET CodigoTemp = Codigo");
            pedidoJolitex.DropColumn("Codigo");
            pedidoJolitex.RenameColumn("CodigoTemp", "Codigo", ColumnType.ShortString);
        }
    }
}
